#include<bits/stdc++.h>
using namespace std;
// #define unordered_map_isvalid

#ifdef unordered_map_isvalid
class Solution {
public:
    bool isValid(string s) {
        int n=s.size();
        if(n%2==1) return false;
        unordered_map<char,char>mp={
            {']','['},
            {'}','{'},
            {')','('}
        };
        stack<char>st;
        for(auto&ch:s)
        {
            if(!st.empty()&&st.top()==mp[ch])
                st.pop();
            else
                st.push(ch);
        }
        return st.empty();
    }
};
#endif